layui.define(['layer', 'form', "upload"], function (exports) {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form();
    //全选
    form.on('checkbox(check)', function (data) {
        if (data.elem.checked) {
            $("input[name='checkbox']").prop("checked", true);
        } else {
            $("input[name='checkbox']").prop("checked", false);
        }
        form.render('checkbox');
    });
    //提交
    $("#btn_save").click(function () {
        if ($.trim($("#title").val()) == '') {
            layer.msg("请填写文件名");
            return false;
        }
        if ($.trim($("#description").val()) == '') {
            layer.msg("请填写文件简介");
            return false;
        }

        if ($.trim($("#accept_id").val()) == '') {
            layer.msg("请填写收件人");
            return false;
        }
        $(this).parents("form").submit();
    })
    //列表多选删除
    $("#btn_del").click(function () {
        var id = "";
        if ($("[name='checkbox']:checked").length > 0) {
            $("[name='checkbox']:checked").each(function () {
                id += "'" + $(this).val() + "',";
            })
            $.ajax({
                type: "post",
                url: "/srv/sdo.php",
                data: {id: id, tpl: "del_file_upload_receive"},
                dataType: "json",
                success: function (res) {
                    if (res.status) {
                        layer.msg(res.tips, {}, function () {
                            location.reload();
                        });
                    } else {
                        layer.msg(res.tips);
                    }
                }
            });

        } else {
            layer.msg("请选择需要删除的选项")
        }
    })
    //列表多选签收
    $("#btn_readers").click(function () {
        var id = "";
        if ($("[name='checkbox']:checked").length > 0) {
            $("[name='checkbox']:checked").each(function () {
                id += "'" + $(this).val() + "',";
            })
            $.ajax({
                type: "post",
                url: "/srv/sdo.php",
                data: {id: id, tpl: "file_upload_readers"},
                dataType: "json",
                success: function (res) {
                    if (res.status) {
                        layer.msg(res.tips, {}, function () {
                            location.reload();
                        });
                    } else {
                        layer.msg(res.tips);
                    }
                }
            });

        } else {
            layer.msg("请选择需要签收的选项")
        }
    })
    //意见反馈
    $(".opinion").click(function () {
        var file_id = $(this).attr("data-id");
        layer.open({
            type: 1,
            btn: ["确定", "取消"],
            title: "意见反馈",
            area: ["500px", "300px"],
            content: "<textarea class='layui-textarea back_views' style='width:96%;height:90%;margin:2% 2%;border:0px soild #000'></textarea>",
            yes: function () {
                var content = $.trim($(".back_views").val());
                if (content) {
                    $.ajax({
                        type: "post",
                        url: "/html/file/srv/back_views.php",
                        data: {id: file_id,content: content},
                        dataType: "json",
                        success: function (res) {
                            if (res.status) {
                                layer.msg(res.tips, {}, function () {
                                    location.reload();
                                });
                            } else {
                                layer.msg(res.tips);
                            }
                        }
                    });
                } else {
                    layer.msg("请填写反馈意见");
                }
            },
        })
    })
    //导出
    $("#btn_out").click(function () {
        var id = "";
        if ($("[name='checkbox']:checked").length > 0) {
            $("[name='checkbox']:checked").each(function () {
                id += $(this).val() + ",";
            })
            location.href = "/html/file/srv/file_export.php?id=" + id;

        } else {
            layer.msg("请选择需要导出的选项")
        }
    })
    exports('file_receive', {});
});